package web.suzy.oj.service.admin.account.impl;

import org.springframework.stereotype.Service;
import web.suzy.oj.common.exception.StatusAccessDeniedException;
import web.suzy.oj.common.exception.StatusFailException;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.common.result.ResultStatus;
import web.suzy.oj.manager.admin.account.AdminAccountManager;
import web.suzy.oj.pojo.dto.LoginDTO;
import web.suzy.oj.pojo.vo.UserInfoVO;
import web.suzy.oj.service.admin.account.AdminAccountService;

import javax.annotation.Resource;

/**
 * YangSuzy 软件工作室
 * 类名: AdminAccountServiceImpl
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/17 16:18
 */
@Service
public class AdminAccountServiceImpl implements AdminAccountService {
    @Resource
    private AdminAccountManager adminAccountManager;

    /**
     * 方法名: login
     * 描述: 管理员登录
     *
     * @param loginDto
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.UserInfoVO>
     * @date 2022/11/17 16:19
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<UserInfoVO> login(LoginDTO loginDto) {
        try {
            return ResultBean.successResponse(adminAccountManager.login(loginDto));
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        } catch (StatusAccessDeniedException e) {
            return ResultBean.errorResponse(e.getMessage(), ResultStatus.ACCESS_DENIED);
        }
    }

    @Override
    public ResultBean<Void> logout() {
        adminAccountManager.logout();
        return ResultBean.successResponse("退出登录成功！");
    }
}
